package com.atguigu.tingshu.order.service.impl;

import com.atguigu.tingshu.model.order.LocalMsg;
import com.atguigu.tingshu.order.mapper.LocalMsgMapper;
import com.atguigu.tingshu.order.mapper.OrderInfoMapper;
import com.atguigu.tingshu.order.service.MqOpsService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Author:huzhongkui
 * Date: 2025-03-28 星期五 15:48:17
 * Description:
 */

@Service
@Slf4j
public class MqOpsServiceImpl implements MqOpsService {

    @Autowired
    private LocalMsgMapper localMsgMapper;

    @Autowired
    private OrderInfoMapper orderInfoMapper;

    @Override
    public void updateLocalMsgStatus(String content) {

        LambdaQueryWrapper<LocalMsg> wrapper = new LambdaQueryWrapper<LocalMsg>();
        wrapper.eq(LocalMsg::getMsgContent, content);
        LocalMsg localMsg = localMsgMapper.selectOne(wrapper);
        if (localMsg != null) {
            localMsg.setStatus(1);
            localMsgMapper.updateById(localMsg);
        }
    }

    @Override
    public void cancelOrder(String orderNo) {

        int count = orderInfoMapper.cancelOrder(orderNo);

        log.info("关闭订单：{}",count>0?"success":"fail");
    }

}
